#include <iostream>
#include <string>

void traditionalMemoryManagement() {
    std::cout << "=== 传统内存管理示例 ===" << std::endl;
    
    // 在堆上分配内存
    int* number = new int(42);
    std::cout << "分配的数字: " << *number << std::endl;
    
    // 分配数组
    int* array = new int[5]{1, 2, 3, 4, 5};
    std::cout << "数组元素: ";
    for(int i = 0; i < 5; i++) {
        std::cout << array[i] << " ";
    }
    std::cout << std::endl;
    
    // 分配对象
    std::string* text = new std::string("Hello, Memory!");
    std::cout << "字符串: " << *text << std::endl;
    
    // 重要：必须手动释放内存！
    delete number;      // 释放单个对象
    delete[] array;     // 释放数组
    delete text;        // 释放字符串对象
    
    std::cout << "内存已释放" << std::endl;
}

int main() {
    traditionalMemoryManagement();
    return 0;
}